home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / SCHEME / GNU / JACALRC / jacal / DOC / grammar < prev    next >
Text File  |  1993-07-01  |  2KB  |  70 lines

  1.  
  2.                   THE LEXER
  3.  
  4. In English.scm there are the lines:
  5. (lex:def-class 70 '(#\^) #f)
  6. (lex:def-class 49 '(#\*) #f)
  7. (lex:def-class 50 '(#\/) #f)
  8. (lex:def-class 51 '(#\+ #\-) #f)
  9. (lex:def-class 20 '(#\|) #f)
  10. (lex:def-class 30 '(#\< #\> #\= #\: #\~) #f)
  11. (lex:def-class 40 '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
  12.            (lambda (l) (string->number (list->string l))))
  13. (lex:def-class 41
  14.         '(#\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M
  15.           #\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z
  16.           #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
  17.           #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z
  18.           #\@ #\_ #\% #\?)
  19.         #f)
  20. (lex:def-class (lambda (chr) (or (eqv? #\" chr) (eof-object? chr)))
  21.         '(#\")
  22.         (lambda (l)
  23.           (lex:read-char) (string->symbol (list->string (cdr l)))))
  24. (lex:def-class 0 (list slib:tab slib:form-feed #\  #\newline) #f)
  25.  
  26. These lines define which character can be grouped into symbols in the
  27. standard input-grammar.  In the first line is only the character ^ and
  28. its class number is not 1 removed from any other.  Therefore it can
  29. only group with itself.  Eg.  ^ ^^ ^^^ ^^^^ ...
  30.  
  31. e5 : a+^^^^-c;
  32.  
  33. e5: ^^^^ + a - c
  34.  
  35. The line (lex:def-class 30 '(#\< #\> #\= #\: #\~) #f) says that any
  36. consecutive combination of < > = : and ~ will be grouped together.
  37.  
  38. 41 is one greater than 40 so a symbol can begin with a class 41
  39. character and continue with either class 41 or class 40 characters.
  40.  
  41. 51 can have subsequent 50 characters; this gives us +/- and -/+.
  42. 50 can have subsequent 49 characters; this gives us /*.
  43.  
  44. Class 0 is special (all the other numbers are arbitrary).  It
  45. designates whitespace.
  46.  
  47. #\" has a function rather than a class number.  This function is #t
  48. when the symbol should end.
  49.  
  50. The last argument to lex:def-class is the function to run on the list
  51. of characters of a symbol.  If #f then a symbol is generated from the
  52. character list.
  53.  
  54.              INSTALLING A GRAMMAR
  55.  
  56. (defgrammar 'mygrammar
  57.   (make-grammar 'mygrammar
  58.         (lambda (grm) (read))        ;the reader
  59.         #f                ;lex-tab
  60.         #f                ;read-tab
  61.         (lambda (sexp grm) (write sexp));the writer
  62.         #f))                ;write-tab
  63.  
  64. The grm arguments are passed the whole grammar (a list of the args
  65. passed to make-grammar).  Lex-tab is used by the lexer if you call it.
  66. The read-tab can be used by the reader if you want it.  the write-tab
  67. contains the templates for the writer.  You can probably use inprint
  68. for the writer (which uses templates like those at the beginning of
  69. English.scm).
  70.